import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'
import index from '../views/index.vue'
import upkeep from '../views/upkeep.vue'
import repairlistinfo from '../views/repairlistinfo.vue'
import indexpage from '../views/indexpage.vue'
import newmaintenance from '../views/newmaintenance.vue'
import staffinfolist from '../views/staffinfolist.vue'
import noticeinformation from '../views/noticeinformation.vue'
import loginuser from '../views/logininfo.vue'
import userlist from '../views/userlist.vue'
import staffinfo from '../views/staffinfo.vue'
import datavpage from '../views/datavpage.vue'
import voide from '../views/voidelist.vue'
import newword from '../views/newword.vue'
import nocitecompont from '../components/nocite.vue'


Vue.use(VueRouter)

const routes = [
  {
    path:'/loginuser',
    component:loginuser  
   },

   {
    path:'/datavpage',
    component:datavpage,
    children:[
      {path:'',
      component:voide
    },
  {
    path:'voide',
    component:voide
  }] 
   },
   {
    path:'/voide',
    component:voide,
   

   },
  {
   path:'/',
   redirect:'/index'
   
  },
  {
   path:'/index',
   component:index,
   children:[
    {path:'',
    component:indexpage
  },
{
  path:'indexpage',
  component:indexpage
},{
  path:'notice',
  component:noticeinformation,
  children:[
    {path:'',
    component:newword
  },
  {
    path:'newword',
    component:newword,
   
  },
  {
    path:'nocitelist/:index',
    component:nocitecompont,
    children:[
      {path:'newword',
    component:newword
  },
    ]
   
  }
   
  ]

},
{
  path:'staffinfo',
  component:staffinfo
},
{
  path:'userlist',
  component:userlist
},


  {path:'upkeep',
  component:upkeep,

  children:[,
    {path:'',
    component:repairlistinfo
  },{
    path:'listinfo/:id',
    component:repairlistinfo,
   
  }
   
  ]
},
{path:'newmaintenance',
component:newmaintenance
},
,{
  path:'staffinfolist',
  component:staffinfolist,
}
   ]


  },

 
]
//防止重复点击路由遇到的问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
}




const router = new VueRouter({
  routes
})

// router.beforeEach((to,from,next)=>{
//   if(to.path!="/loginuser"){
//     var token=localStorage.getItem("userInfo")
//     if(token){
//       next()//访问的是后台主页，且有token值
//     }
//     else{ 
//       next('/loginuser')
//     }
//    } else{
//       next()
//    }
// })

export default router
